package org.mall.modules.promotion.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mall.modules.promotion.entities.CouponCardDO;
import org.mall.modules.promotion.entities.CouponCardSDO;
import org.mall.modules.promotion.entities.CouponDO;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CouponCardMapper {

    CouponCardDO selectById(@Param("id") Integer id);

    List<CouponCardDO> selectListByUserIdAndStatus(@Param("userId") String userId,
                                                   @Param("status") Integer status);

    List<CouponCardDO> selectListByPage(@Param("userId") String userId,
                                        @Param("status") Integer status,
                                        @Param("offset") Integer offset,
                                        @Param("limit") Integer limit);

    Integer selectCountByPage(@Param("userId") String userId,
                              @Param("status") Integer status);

    int selectCountByUserIdAndTemplateId(@Param("userId") String userId,
                                         @Param("templateId") Integer templateId);

    void insert(CouponCardDO couponCardDO);

    int update(CouponCardDO couponCardDO);

    int updateByIdAndStatus(@Param("id") Integer id,
                            @Param("status") Integer status,
                            @Param("updateObj") CouponCardDO updateObj);
    /**
     * 优惠卷逻辑删除
     * @param id
     * @return
     */
    @Update("update coupon_card set is_delete = 1 where id = #{id}")
    boolean updateCouponById(Integer id);
    /**
     * 优惠卷批量逻辑删除
     * @param ids
     * @return
     */
    boolean updateCouponByIds(@Param("ids") List<String> ids);


    boolean updateCouponExpireByIds(@Param("ids") List<Integer> ids);

    /**
     * 保存优惠卷
     * @param couponCardSDO
     * @return
     */
    boolean couponInsert(CouponCardSDO couponCardSDO);


    /**
     * 优惠卷的分页查询---查询优惠卷数据
     * @param takeType
     * @param title
     * @param status
     * @param preferentialType
     * @param offset
     * @param limit
     * @return
     */
    List<CouponDO> selectListTBPage(@Param("takeType") Integer takeType,
                                    @Param("title") String title,
                                    @Param("status") Integer status,
                                    @Param("preferentialType") Integer preferentialType,
                                    @Param("offset") Integer offset,
                                    @Param("limit") Integer limit,
                                    @Param("isDelete") Integer isDelete);

    /**
     * 优惠卷的分页查询---查询优惠卷数据
     * @param takeType
     * @param title
     * @param status
     * @param preferentialType
     * @return
     */
    Integer selectCountTBPage(@Param("takeType") Integer takeType,
                              @Param("title") String title,
                              @Param("status") Integer status,
                              @Param("preferentialType") Integer preferentialType,
                              @Param("isDelete") Integer isDelete);
    /**
     * 通过id查看优惠卷信息
     * @param id
     * @return
     */
    CouponCardSDO queryCouponInfo(@Param("id") String id);

    int selectCountByUserId(@Param("userId") String userId);
}
